import SendMsg from "@/api/SendMsg";
import {message} from "ant-design-vue";
import i18n from "../../../i18n";

const JsNormalLots = {
    namespaced: true,
    state: {
        // table数据
        dataSource: [],
        waferDataSource: [],
        waferMapDataSource: [],
        // 查询条件
        queryForm: {
           type: undefined,
           lotId: '',
           state: 'non-Hold'
        },
        typeList:[
            { value: 'WAT', lable: 'WAT' },
            { value: 'CP' , lable: 'CP'},
            { value: 'other' , lable: 'other'}
        ],
        loadTable: false,
        normalLotsModalVisible: false,
        dataPagination: {
            current: 1,
            pageSize: 14,
            total: 0,
            showTotal: (total, range) => {
                return i18n.t('menuItem.total')+` ${total} `+i18n.t('menuItem.term')
            },
        },
        // table选中行
        selectRow: {},
        clickLotId: '',
    },
    mutations: {
        //查询table
        queryLot(state) {
            // if(!state.queryForm.type){
            //     message.warn(i18n.t('menuItem.pleaseCheckType'))
            //     return
            // }

            let inTrx = {
                trxId: "normalLot",
                actionFlg: "Q",
                pageSize: state.dataPagination.pageSize,
                pageNum: state.dataPagination.current,
                ...state.queryForm
            };
            state.dataSource = []
            state.loadTable = true
            SendMsg.sendPostTrx(inTrx).then((res) => {
                let outTrx = res.data;
                if ('0000000' === outTrx.rtnCode) {
                    if(outTrx.normalLotOAList){
                        state.dataSource = outTrx.normalLotOAList.map((item, index) => {
                            item.key = (index + 1);
                            return item;
                        });
                    }
                }
                state.dataPagination.total = outTrx.tblCnt;
            }).finally(() => {
                state.waferDataSource = []
                state.loadTable = false
            });
        },

        setDataPagination(state, val) {
            state.dataPagination = val;
        },
        clickCell(state, record) {
            state.selectRow = record
            let inTrx = {
                trxId: "normalLot",
                actionFlg: "QWAFER",
                lotId: state.selectRow.lotId
            };
            state.waferMapDataSource = []
            SendMsg.sendPostTrx(inTrx).then((res) => {
                let outTrx = res.data;
                if ('0000000' === outTrx.rtnCode) {
                    if(outTrx.normalLotOBList){
                        state.waferMapDataSource = outTrx.normalLotOBList.map((item, index) => {
                            item.key = (index + 1);
                            return item;
                        });
                    }
                    state.clickLotId = state.selectRow.lotId
                }
            }).finally(() => {
            });
            state.normalLotsModalVisible = true
        },
        queryWaferTableData(state,val){
            let inTrx = {
                trxId: "normalLot",
                actionFlg: "QWAFER",
                lotId: val
            };
            state.waferDataSource = []
            SendMsg.sendPostTrx(inTrx).then((res) => {
                let outTrx = res.data;
                if ('0000000' === outTrx.rtnCode) {
                    if(outTrx.normalLotOBList){
                        state.waferDataSource = outTrx.normalLotOBList.map((item, index) => {
                            item.key = (index + 1);
                            return item;
                        });
                    }
                }
            }).finally(() => {
            });
        },
        modalConfirm(state){
            state.waferDataSource = state.waferMapDataSource
            state.normalLotsModalVisible = false
        },
        modalCancel(state){
            state.waferMapDataSource = []
            state.normalLotsModalVisible = false
        },
        // 清空弹窗数据
        cleanAll(state) {
            state.dataSource = [],
            state.waferDataSource = [],
            state.queryForm = {
                type: '',
                lotId: '',
            },
            state.dataPagination = {
                current: 1,
                    pageSize: 14,
                    total: 0,
                    showTotal: (total, range) => {
                        return i18n.t('menuItem.total')+` ${total} `+i18n.t('menuItem.term')
                },
            }
        },
    },
    getters: {},
    action: {}
}
export default JsNormalLots;
